﻿Imports System.Xml

Namespace Stories
	Public Class XmlElement
		Inherits Child

		Public Sub New()
			Me.Children = New List(Of Child)
		End Sub

		Public Overrides Function ToString() As String
			Return Me.Self
		End Function

		Public Property Self As String
		Public Property MarkupTag As String
		Public Property XmlContent As String
		Public Property NoTextMarker As Boolean?

		Public Property Children As List(Of Child)

		Public Shared Function ReadXml(reader As XmlReader) As XmlElement
			Dim xe As New XmlElement()

			xe.Self = reader.GetAttribute("Self")
			xe.MarkupTag = reader.GetAttribute("MarkupTag")
			xe.XmlContent = reader.GetAttribute("XMLContent")
			xe.NoTextMarker = Parser.ParseBoolean(reader.GetAttribute("NoTextMarker"))

			While reader.Read()
				Select Case reader.Name
					Case "XMLAttribute"
						xe.Children.Add(XmlAttribute.ReadXml(reader))
					Case "XMLElement"
						If reader.NodeType = XmlNodeType.EndElement Then
							Exit While
						Else
							xe.Children.Add(XmlElement.ReadXml(reader))
						End If
					Case "XMLComment"
						xe.Children.Add(XmlComment.ReadXml(reader))
					Case "XMLInstruction"
						xe.Children.Add(XmlInstruction.ReadXml(reader))
					Case "Table"
						xe.Children.Add(Table.ReadXml(reader))
					Case "Footnote"
						xe.Children.Add(Footnote.ReadXml(reader))
					Case "Note"
						xe.Children.Add(Note.ReadNote(reader))
					Case "GaijiOwnedItemObject"
						xe.Children.Add(GaijiOwnedItemObject.ReadXml(reader))
					Case "TextVariableInstance"
						xe.Children.Add(TextVariableInstance.ReadXml(reader))
						'add more cases here
					Case "HiddenText"
						xe.Children.Add(HiddenText.ReadXml(reader))
						'add more cases here
					Case "ParagraphStyleRange"
						xe.Children.Add(ParagraphStyleRange.ReadXml(reader))
					Case "CharacterStyleRange"
						xe.Children.Add(CharacterStyleRange.ReadXml(reader))
					Case "Content"
						xe.Children.Add(New Content(reader.ReadString()))
					Case "Br"
						xe.Children.Add(New Br())

					Case ""
					Case ""
					Case ""
					Case ""
					Case ""
					Case ""
					Case ""
					Case ""
					Case ""
					Case Else

				End Select
			End While

			Return xe
		End Function
	End Class
End Namespace